utils.on(tbody,'click',function(e){
    var target = e.target;
    if(Array.from(target.classList).includes('btn-del')){
        console.log(target);
        if(confirm("确定是否删除")){
        const tr = target.parentNode.parentNode;
        const id = tr.getAttribute('data-id');
        console.log(id);
        utils.fetch("./api/shop/delete.php",{id}).then(resp => {
            console.log(resp.code);
            if(resp.code === 200){
                select();
            }
        })

    }
    }
    if(Array.from(target.classList).includes('btn-edit')){
        console.log(target);
        var tr = target.parentNode.parentNode;
        tr.classList.add('edit');
        var span = tr.querySelectorAll('span');
        var input = tr.querySelectorAll('input');
        for(var i = 0;i < span.length;i++){
            input[i].value = span[i].innerHTML;
        }
    }
    if(Array.from(target.classList).includes('btn-ok')){
        var tr = target.parentNode.parentNode;
        var input = tr.querySelectorAll('input');
        
        const name = input[0].value,
              price = input[1].value,
              num = input[2].value,
              id = tr.getAttribute("data-id");  
    utils.fetch("./api/shop/change.php",{name,price,num,id}).then((resp) => {
        console.log(resp);
        if(resp.code === 200){
            
                tr.classList.remove('edit');
                select();
        }
    })
    }
    if(Array.from(target.classList).includes('btn-cancel')){
        var tr = target.parentNode.parentNode;
        tr.classList.remove('edit');
    }
})

